extends Enemy

var baby = preload("res://Scenes/enemy/baby_spider.tscn")

var spawn_count = 100
var spawned = 0

func _ready() -> void:
    super._ready()
    data = Global.enemy_data[6]

func _hurt(damage) -> void:
    if data["CURRENT_HP"] - damage <= 0:
        for i in range(randi_range(3, 5)): # 每帧实例化2个小蜘蛛
            if spawned >= spawn_count:
                break
            spawn_single_object()
            spawned += 1
        queue_free()
    else:
        data["CURRENT_HP"] -= damage
        for i in range(2): # 每帧实例化2个小蜘蛛
            if spawned >= spawn_count:
                break
            spawn_single_object()
            spawned += 1

func spawn_single_object():
    var babe = baby.instantiate()
    self.get_parent().add_child(babe)
    babe.position = position
    babe.position += Vector2(randf_range(-128, 128), randf_range(-128, 128))